Skip to content

Durga arrays js#537

Open
Saidurgasatturi wants to merge 2 commits intoaptyInc:mainfrom
Saidurgasatturi:durga-arrays-js
Open

Durga arrays js#537
Saidurgasatturi wants to merge 2 commits intoaptyInc:mainfrom
Saidurgasatturi:durga-arrays-js

Conversation

@Saidurgasatturi
Copy link
Copy Markdown

@Saidurgasatturi Saidurgasatturi commented Nov 3, 2025

Terms and Conditions

  • I Accept losing points if my PR does not follow the best practices mentioned below, which will impact my overall performance in training

HTML Best Practices

  • File Naming Convention:

  • Follow consistent and descriptive naming (e.g., dashboard.html, user-profile.html).

  • Use lowercase letters and hyphens instead of spaces.

  • Page Title:

  • Ensure the <title> tag is descriptive and aligns with the page content.

  • Include meaningful keywords for SEO if applicable.

  • Semantic Markup:

  • Use appropriate tags like <header>, <footer>, <section>, <article> for better readability and accessibility.

  • Accessibility Standards:

  • Ensure the use of alt attributes for images and proper labels for form elements.

  • Use ARIA roles where necessary.

  • Validation:

  • Ensure the code passes HTML validation tools without errors or warnings.

  • Structure and Indentation:

  • Maintain consistent indentation and proper nesting of tags.

  • Attributes:

  • Ensure all required attributes (e.g., src, href, type, etc.) are correctly used and not left empty.

CSS Best Practices

  • File Organization:

  • Use modular CSS files if applicable (e.g., base.css, layout.css, theme.css).

  • Avoid inline styles unless absolutely necessary.

  • Naming Conventions:

  • Use meaningful class names following BEM or other conventions (e.g., block__element--modifier).

  • Code Reusability:

  • Avoid duplicate code; use classes or mixins for shared styles.

  • Responsive Design:

  • Ensure proper usage of media queries for mobile, tablet, and desktop views.

  • Performance Optimization:

  • Minimize the use of unnecessary CSS selectors.

  • Avoid overly specific selectors and ensure selectors are not overly deep (e.g., avoid #id .class1 .class2 p).

  • Consistency:

  • Follow consistent spacing, indentation, and use of units (rem/em vs. px).

  • Maintain a single coding style (e.g., always use double or single quotes consistently).

Javascript Best Practices

  • File Organization:

  • Ensure scripts are modular and logically separated into files if needed.

  • Avoid mixing inline JavaScript with HTML.

  • Logic Optimization:

  • Check for redundancy and ensure the code is optimized for performance.

  • Avoid unnecessary API calls or DOM manipulations.

  • Solution Approach:

  • Confirm that the code solves the given problem efficiently.

  • Consider scalability for future enhancements.

  • Readability:

  • Use clear variable and function names.

  • Add comments for complex logic or algorithms.

  • Error Handling:

  • Ensure proper error handling for API calls or user input validation.

  • Code Quality:

  • Check for potential bugs (e.g., missing await, mishandling of null/undefined values).

  • Avoid unnecessary console.log statements in production code.

  • Security:

  • Avoid hardcoding sensitive data.

  • Sanitize user input to prevent XSS and other vulnerabilities.

  • Best Practices:

  • Use const and let instead of var.

  • Follow ES6+ standards where applicable.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @Saidurgasatturi, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a substantial collection of new web development assignments, primarily focusing on core JavaScript concepts related to arrays, objects, and strings. It also includes foundational data structure implementations (Stack and Queue), advanced CSS layouts and animations, and a basic personal homepage project. The changes aim to provide interactive examples and solutions for various programming challenges, enhancing the learning resources available.

Highlights

  • New CSS Advanced Assignments: Introduced two new CSS assignments: one for advanced layout with header, nav, main, article, aside, and footer elements, including responsive design via media queries; and another demonstrating CSS animations and media queries with a bouncing box.
  • New HTML Personal Homepage Project: Added a new HTML file for a personal homepage, featuring sections for 'About Me', 'Education', 'Skills', and a contact form, showcasing basic HTML structure and semantic elements.
  • Extensive JavaScript Array Manipulations: Implemented various JavaScript array-focused assignments, including a custom array flatten function, array chunking, removing duplicates, finding the most frequent element, swapping values using array destructuring, comparing loop performance, and combining arrays with rest/spread operators and method chaining (filter, map, reduce).
  • Comprehensive JavaScript Object Operations: Added several JavaScript assignments demonstrating object manipulation, such as dynamic key handling, deep cloning of nested objects, prototype-based inheritance between 'Person' and 'Employee' objects, and a recursive deep merge function for objects, along with method chaining in classes.
  • Diverse JavaScript String Utilities: Included new JavaScript assignments covering string operations, including calculating word lengths, finding first and last characters, replacing escape sequences, sorting characters, using template literals for greetings, retrieving Unicode values, and string padding.
  • Fundamental Data Structure Implementations: Introduced interactive web pages demonstrating the implementation and usage of two core data structures: Stack (with push, pop, peek, isEmpty) and Queue (with enqueue, dequeue, peek, isEmpty).
  • Matrix Transposition Program: Added a JavaScript program to transpose a user-inputted matrix, demonstrating multi-dimensional array operations.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a comprehensive set of assignments covering HTML, CSS, and JavaScript. The submissions demonstrate a good understanding of the core concepts. However, there are several areas for improvement across the files. My review focuses on enhancing code quality by addressing violations of best practices (such as the separation of concerns between HTML and JavaScript), improving the efficiency of several algorithms, and fixing a few bugs. The feedback aims to be constructive and help elevate the code to a more professional standard.

Comment on lines +4 to +6
const output = input
.replace(/\\n/g, "\\\\n")
.replace(/\\t/g, "\\\\t");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The logic for replacing escape sequences is incorrect. When a user enters a newline or tab in a textarea, the JavaScript string contains the actual control character (e.g., \n), not the literal two-character string \\n. Your code searches for the literal string \\n and replaces it, which won't work as intended. To visually represent these characters, you need to replace the control characters with their string representations.

Suggested change
const output = input
.replace(/\\n/g, "\\\\n")
.replace(/\\t/g, "\\\\t");
const output = input
.replace(/\n/g, "\\n")
.replace(/\t/g, "\\t");

Comment on lines +11 to +16
const uniqueArray = [];
for (let num of combined) {
if (!uniqueArray.includes(num)) {
uniqueArray.push(num);
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current implementation for finding unique elements uses a loop with Array.prototype.includes(), which results in a time complexity of O(n^2). For large arrays, this can be very slow. A more modern and efficient approach is to use a Set, which only stores unique values and provides O(n) performance for this operation.

Suggested change
const uniqueArray = [];
for (let num of combined) {
if (!uniqueArray.includes(num)) {
uniqueArray.push(num);
}
}
const uniqueArray = [...new Set(combined)];

function transposeMatrix(matrix) {
let transposed = [];

for (let i = 0; i < matrix[0].length; i++) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This code assumes that the matrix will always have at least one row (matrix[0]). If an empty matrix [] is passed, matrix[0].length will throw a TypeError. It's good practice to add a guard clause to handle this edge case.

  if (!matrix || matrix.length === 0 || matrix[0].length === 0) {
    return [];
  }
  for (let i = 0; i < matrix[0].length; i++) {

Comment on lines +4 to +8
for (let i = 0; i < arr.length; i++) {
if (!uniqueArr.includes(arr[i])) {
uniqueArr.push(arr[i]);
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using a loop with includes() to find unique elements has a time complexity of O(n^2), which can be inefficient for large arrays. A more performant and concise way to achieve this is by using a Set.

  return [...new Set(arr)];


function deepMerge(target, source) {

for (let key in source) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The for...in loop iterates over all enumerable properties of an object, including those inherited from its prototype. This can lead to unexpected behavior or bugs if the object's prototype chain contains enumerable properties. To avoid this, you should always include a hasOwnProperty check to ensure you are only processing the object's own properties.


function pushElement() {
const input = document.getElementById("element").value;
if (input === "") {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It's a best practice to use textContent instead of innerText when you don't need to be aware of the rendered appearance of the text. textContent has better performance as it doesn't trigger reflows. This applies to other uses of innerText in this file as well.

Suggested change
if (input === "") {
if (input === "") {
document.getElementById("result").textContent = "⚠️ Please enter a value to push.";

return;
}

let wordsArray = input.split(",").map(word => word.trim()).filter(Boolean);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The .filter(Boolean) is a good way to remove empty strings that might result from trailing commas. However, if the user enters something like a,,b, split(',') will produce ['a', '', 'b']. The trim() call on the empty string doesn't change it, so filter(Boolean) correctly removes it. This is good, but it's worth noting that this handles empty entries between commas.

</section>
<section id="contact">
<h2>Contact Me</h2>
<form>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The <form> tag is missing the action and method attributes. The action attribute specifies where to send the form-data when a form is submitted, and method specifies the HTTP method to use (e.g., "GET" or "POST"). Including these attributes is a best practice as it makes the form's purpose and behavior clear, even in a static example.

Suggested change
<form>
<form action="#" method="post">

Comment on lines +2 to +5
const freqMap = arr.reduce((acc, num) => {
acc[num] = (acc[num] || 0) + 1;
return acc;
}, {});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using reduce to create a frequency map is a good approach. It's concise and functional.

Comment on lines +7 to +55
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background: #f0f0f0;
}
.box {
width: 150px;
height: 150px;
background: #3498db;
border-radius: 10px;
display: flex;
justify-content: center;
align-items: center;
color: white;
font-weight: bold;
animation: bounce 2s infinite;
}
@keyframes bounce {
0%, 100% {
transform: translateY(0);
}
50% {
transform: translateY(-50px);
}
}
@media (max-width: 768px) {
.box {
width: 120px;
height: 120px;
font-size: 14px;
background: #e67e22;
}
}

@media (max-width: 480px) {
.box {
width: 90px;
height: 90px;
font-size: 12px;
background: #2ecc71;
}
}
</style>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The PR description includes a checklist for best practices, which states to "Avoid inline styles unless absolutely necessary" and "Use modular CSS files". Placing a large block of CSS within a <style> tag in the HTML file goes against the principle of separation of concerns, making the code harder to maintain. It is recommended to move this CSS to an external stylesheet.

@gemini-code-assist
Copy link
Copy Markdown

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant